using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerGroundState : PlayerState
{
    // Start is called before the first frame update
    public PlayerGroundState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName) : base(_player, _stateMachine, _animBoolName)
    {
    }

    public override void Enter()
    {
        base.Enter();
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();
        // 按下R键进入黑洞技能状态
        if (Input.GetKeyDown(KeyCode.R) && player.skill.blackhole.blackholeUnlocked)
        {
            if (player.skill.blackhole.cooldownTimer > 0)
            {
                player.fx.CreatePopUpText("技能冷却中");
                return;
            }
            stateMachine.ChangeState(player.blackHole);
        }
        // 按下鼠标右键瞄准
        if (Input.GetKeyDown(KeyCode.Mouse1) && HasNoSword() && player.skill.sword.swordUnlocked)
        {
            stateMachine.ChangeState(player.aimSword);
        }
        // 按下K键进行格挡
        if (Input.GetKeyDown(KeyCode.K) && player.skill.parry.parryUnlocked)
        {
            stateMachine.ChangeState(player.counterAttack);
        }
        // 按下J键进入攻击状态
        if (Input.GetKey(KeyCode.J))
        {
            stateMachine.ChangeState(player.primaryAttack);
        }
        // 不站在地面就进入空中状态
        if (!player.IsGroundDetected())
        {
            stateMachine.ChangeState(player.airState);
        }
        // 站在地面按下空格键起跳进入跳跃状态
        if (Input.GetKeyDown(KeyCode.Space) && player.IsGroundDetected())
        {
            stateMachine.ChangeState(player.jumpState);
        }

    }

    // 进入瞄准状态钱判断有没有扔出去的剑
    public bool HasNoSword()
    {
        if (!player.sword)
        {
            return true;// 没有则允许瞄准
        }
        player.sword.GetComponent<Sword_Skill_Controller>().ReturnSword();// 有剑调用剑上返回剑的方法
        return false;
    }
}
